package main

import (
	"flag"
	"fmt"
	"io"
	"log"
	"time"
	"tinp/client/client"
	"tinp/mylog"
)

var (
	clientId   string
	serverAddr string
)

const retryIntervalSecond = time.Second * 3

func init() {

	flag.StringVar(&clientId, "client_id", "", "客户端ID")
	flag.StringVar(&serverAddr, "server_addr", "", "服务器地址")
	flag.Parse()
	if clientId == "" {
		log.Fatalln("客户端ID不能为空!!!")
		return
	}
	if serverAddr == "" {
		log.Fatalln("服务器地址不能为空!!!")
		return
	}
}
func main() {
	c := client.NewClient(clientId, serverAddr)

	for {
		err := c.Run()
		if err != nil && err != io.EOF {
			mylog.Logger.Errorf(fmt.Sprint(err))
		}
		mylog.Logger.Warnf("正在重连服务器: %s", serverAddr)
		time.Sleep(retryIntervalSecond)
	}
}
